<?php
class Order
{
	public $_book;
	
	function __construct()
	{
		$this->_book = new Crb_Db('order');
	}

	
	function getList()
	{
		$Rows = $this->_book->fetchAll(  $this->_book->select()->order('created desc')   );
		
		if ($Rows) return $Rows->toArray();
		return array();
	}
	
	
	function create($From, $Till, $Room, $Params)
	{
		$book = new Book();
		
	    $Row = $this->_book->createRow(array('from'=>$From, 'till'=>$Till, 'room'=>$Room,'approved'=>0,'params'=>serialize($Params),'created'=>new Zend_Db_Expr("NOW()")));
		
		
		//TODO: recheck
		
		
		
		$Row->save();
		return $Row->id;
	}
	
	function get($id)
	{
		$Row = $this->_book->find($id)->current();
		$Item = $Row->toArray();
		$Item['params'] = unserialize($Item['params']);
		return $Item;  
	}
	
	
	function approve($id)
	{
		$Row = $this->_book->find($id)->current();
		$Row->approved = 1;
		$Row->save();
	}

	function cancel($id)
	{
		$Row = $this->_book->find($id)->current();
		$Row->delete();
	}
	
	function removeAll()
	{
	    $this->_book->delete("1");
	}
	
	
	
}